[id].client.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="pb-120">
  3. <TravelProjectDetailBanner
  4. :banner-list="detailData?.tourismFile?.fileUrlsAfterConvert"
  5. />
  6. <TravelProjectDetailBaseInfo :detail-data="detailData" />
  7. <div class="h-10 bg-[#E6E6E6]"></div>
  8. <div class="px-15">
  9. <TravelProjectDetailBookInfo
  10. v-model:startDate="bookInfo.startDate"
  11. v-model:adultNumber="bookInfo.adultNumber"
  12. v-model:childrenNumber="bookInfo.childrenNumber"
  13. :calendar-data="calendarData"
  14. :detail-data="detailData"
  15. />
  16. <TravelProjectDetailSellingPoint
  17. v-if="detailData?.sellingPoint"
  18. :detail-data="detailData"
  19. class="mt-20"
  20. />
  21. <TravelProjectDetailSpecialTips class="mt-20" />
  22. <TravelProjectDetailDetails :detail-data="detailData" class="mt-20" />
  23. </div>
  24. <TravelProjectDetailBottomBar
  25. :total-price="totalPrice"
  26. :detail-data="detailData"
  27. :loading="submitLoading"
  28. @onOk="handleSubmit"
  29. />
  30. </div>
  31. </template>
  32. <script setup>
  33. const id = useRouteParam("id");
  34. const bookInfo = reactive({
  35. startDate: null,
  36. adultNumber: 1,
  37. childrenNumber: 0,
  38. });
  39. const { data: detailData, status } = await useMyFetch(
  40. `website/tourism/project/detail?id=${id.value}`
  41. );
  42. const dayjs = useDayjs();
  43. const calendarData = ref({});
  44. async function getCalendarData() {
  45. const { data } = await request("/website/tourism/project/viewDatePrice", {
  46. query: {
  47. projectId: id.value,
  48. },
  49. });
  50. calendarData.value = data.tourismProjectDatePriceVos ?? {};
  51. const minDay = dayjs.min(
  52. Object.keys(calendarData.value).map((e) => dayjs(e))
  53. );
  54. bookInfo.startDate =
  55. minDay === null ? null : dayjs(minDay).format("YYYY-MM-DD");
  56. }
  57. const totalPrice = ref("");
  58. watch(
  59. bookInfo,
  60. () => {
  61. // 计算总价
  62. const calendarInfo = calendarData.value[bookInfo.startDate] ?? {
  63. adultPrice: 0,
  64. childrenPrice: 0,
  65. };
  66. totalPrice.value = `${
  67. bookInfo.adultNumber * calendarInfo.adultPrice +
  68. bookInfo.childrenNumber * calendarInfo.childrenPrice
  69. }`;
  70. },
  71. { deep: true }
  72. );
  73. const route = useRoute();
  74. const useAuth = useAuthStore();
  75. const { token } = storeToRefs(useAuth);
  76. async function handleSubmit() {
  77. if (!token.value) {
  78. await navigateTo({
  79. path: "/login",
  80. replace: true,
  81. query: {
  82. redirect: route.fullPath,
  83. },
  84. });
  85. return;
  86. }
  87. handleSubmitInfo();
  88. }
  89. const submitLoading = ref(false);
  90. function handleSubmitInfo() {
  91. submitLoading.value = true;
  92. request("website/tourism/project/bookProject", {
  93. method: "post",
  94. body: {
  95. tourBookInfoDto: {
  96. projectId: id.value,
  97. type: "1",
  98. ...bookInfo,
  99. },
  100. },
  101. })
  102. .then(({ data }) => {
  103. submitLoading.value = false;
  104. if (data === 1) {
  105. showDialog({
  106. title: "预定成功",
  107. message: "恭喜预定成功我们会尽快和您取得联系",
  108. }).then(() => {});
  109. } else if (data === 2) {
  110. showDialog({
  111. title: "您已预定",
  112. message: "我们会尽快和您取得联系",
  113. }).then(() => {
  114. // on close
  115. });
  116. }
  117. })
  118. .catch(() => {
  119. submitLoading.value = false;
  120. });
  121. }
  122. onMounted(() => {
  123. getCalendarData();
  124. });
  125. // watch(
  126. // bookInfo,
  127. // () => {
  128. // console.log(bookInfo);
  129. // },
  130. // { deep: true }
  131. // );
  132. </script>
  133. <style lang="scss" scoped></style>